#!/bin/bash

# 
# Installation of system monitor.
# 
# Target platform: Based on Ubuntu(Ubuntu Kylin/Ubuntu Desktop/Linux Mint/ZorinOS/DeepinOS), include graphical interface, and not applicable to any server version.
# Create date: 2019/06/27
# Create user: SteveJrong
# File version: 1.0.0

# Import some shells.
. common/common.sh

# ######################### start of variables #########################
APP_PACKAGE_KEYWORD_1="gnome-system-monitor"
UBUNTU_OS_DISTRIBUTION_NAME="ubuntu"
# ######################### end of variables #########################

# ######################### start of functions #########################
# ######################### end of functions #########################

# ######################### start of install system monitor #########################
echo '------------------------- Starting install system monitor.'

echo '------------------------- Installation status checked.'
osType=`head -n 1 /etc/issue`
osTypeLowerCase=`echo $osType | tr '[A-Z]' '[a-z]'`
if [[ $osTypeLowerCase =~ $UBUNTU_OS_DISTRIBUTION_NAME ]]; then
	# The current system is Ubuntu, need to uninstalld gnome-system-monitor first, must to be use 'snap' command to uninstall it.

	fullName=
	eval findAppPackageFullNameByKeyword $APP_PACKAGE_KEYWORD_1 $APP_PACKAGE_INSTALLATION_MODE_SNAP fullName

	if [[ -n $fullName ]]; then
		echo -e "------------------------- Starting uninstall old app package by 'snap' command:" $fullName
		sudo snap remove $fullName
	else
		outputWarnMsg "App package not installation or query failure!"
	fi
fi

# The current system is non Ubuntu, use 'apt' command to uninstall.
fullName=
eval findAppPackageFullNameByKeyword $APP_PACKAGE_KEYWORD_1 $APP_PACKAGE_INSTALLATION_MODE_DPKG_APT fullName

if [[ -n $fullName ]]; then
	echo -e "------------------------- Starting uninstall old app package by 'apt' command:" $fullName
	sudo sudo apt-get remove --purge $fullName
else
	outputWarnMsg "App package not installation or query failure!"
fi
echo -e "------------------------- Done.\n"
sleep 5

echo '------------------------- Installing application package.'
sudo sudo apt-get install $APP_PACKAGE_KEYWORD_1
echo -e "------------------------- Done.\n"

outputSuccessMsg "Installation is complete!"

echo '------------------------- Installing application package.'
sudo sudo apt-get install $APP_PACKAGE_KEYWORD_1
echo -e "------------------------- Done.\n"

outputSuccessMsg "Install system monitor is complete!"
# ######################### end of install system monitor #########################